<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      top="8vh"
      width="40%"
      :visible.sync="dialogVisible"
      center
      @close="handleCancel"
    >
      <div class="el-dialog-div">
      <el-form
        :rules="rules"
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="120px"
        style="height: 90%;"
      >
          <el-form-item label="上级菜单" prop="parentId"  class="is-required">
            <MenuCascader ref="menuCascader" v-model="temp.parentId"/>
          </el-form-item>

          <el-form-item label="菜单标题" prop="menuTitle"  class="is-required">
            <el-input v-model="temp.menuTitle" placeholder="菜单标题" />
          </el-form-item>

          <el-form-item label="菜单名" prop="menuName"  class="is-required">
            <el-input v-model="temp.menuName" placeholder="菜单名" />
          </el-form-item>

          <el-form-item label="菜单路径" prop="menuPath"  class="is-required">
            <el-input v-model="temp.menuPath" placeholder="菜单路径" />
          </el-form-item>

          <el-form-item label="菜单图标" prop="menuIcon"  class="is-required">
            <el-input v-model="temp.menuIcon" placeholder="菜单图标" />
          </el-form-item>

          <el-form-item label="菜单类型" prop="menuType" class="is-required">
            <el-radio-group v-model="temp.menuType">
              <el-radio-button label="1">菜单</el-radio-button>
              <el-radio-button label="2">权限</el-radio-button>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="组件" prop="component"  class="is-required">
            <el-input v-model="temp.component" placeholder="组件" />
          </el-form-item>

          <el-form-item label="权限标识" prop="perms"  class="is-required">
            <el-input v-model="temp.perms" placeholder="权限标识" />
          </el-form-item>

      </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { addMenu, getMenuTree } from '@/api/system/menu/menu'
import {setRequiredFields} from "@/utils";
import MenuCascader from '@/views/common/system/menuCascader'
const requiredFields = []
export default {
  name: "addForm",
  components: { MenuCascader },
  data() {
    return {
      rules: setRequiredFields(requiredFields),
      dialogVisible: false,
      temp: {
        menuId:'',
        parentId:'',
        menuTitle:'',
        menuName:'',
        menuIcon:'',
        menuPath:'',
        menuUrl:'',
        component:'',
        perms:'',
        menuType:1,
      },
    }
  },
  mounted() {

  },
  methods: {
    open() {
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs['menuCascader'].fetchData()
      })
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          addMenu(this.temp).then(response =>{
            this.handleCancel()
            this.$emit('ok', response.data)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    handleCancel() {
      //初始化
      this.temp = this.$options.data().temp
      this.dialogVisible = false
      this.$refs['dataForm'].resetFields();
    }
  },
}
</script>

<style scoped>

</style>
